<template>
	<view>
		<view class="setting-card mt-4">
			
			
			<view @click="handSettingCommission()" style="background:#fff;" class="set-item d-flex align-center mb-2 justify-space-between">
				<view class="set-title d-flex align-center">
					
					<text class="font-18">新增代理自动分佣</text>
				</view>
				<view class="">
					<uni-icons type="right" color="#000" size="24"></uni-icons>
				</view>
			</view>
			<view @click="handSettingGoods()" style="background:#fff;" class="set-item d-flex align-center mb-2 justify-space-between">
				<view class="set-title d-flex align-center">
					
					<text class="font-18">新增产品自动分佣</text>
				</view>
				<view class="">
					<uni-icons type="right" color="#000" size="24"></uni-icons>
				</view>
			</view>
			<view @click="handSettingShe()" style="background:#fff;" class="set-item d-flex align-center mb-2 justify-space-between">
				<view class="set-title d-flex align-center">
					<image class="mr-2" style="width:80rpx;height:80rpx" src="../../static/homeImages/setting-icon.png" mode=""></image>
					<text class="font-18">退出</text>
				</view>
				<view class="">
					<uni-icons type="right" color="#000" size="24"></uni-icons>
				</view>
			</view>
		</view>
		<uni-popup ref="popupPiliangfy" mode="center" :close-on-click-overlay="true" closeable border-radius="10px">
			<view class="Piliangfypopup" style="">
				<view class="title">
					<text class="">代理(直接代理)</text>
				</view>
				<view class="Piliangfypopup-input">
					<input type="text" v-model="commission_money" placeholder="请输入批量分佣百分比" />
				</view>
				<view style="width: 80%;margin-left: 10%;">
					<text>说明:一次性批量分配给所有产品,例如:输入10%即可赚取下游10%的利润</text>
				</view>
				<view class="d-flex justify-space-around">
					<button size="mini" type="default" @click="submitFY">取消</button>
					<button size="mini" type="primary" @click="submitFYA">确认</button>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popupPiliang" mode="center" :close-on-click-overlay="true" closeable border-radius="10px">
			<view class="Piliangfypopup" style="">
				<view class="title">
					<text class="">商品(直接商品)</text>
				</view>
				<view class="Piliangfypopup-input">
					<input type="text" v-model="commission_money" placeholder="请输入批量分佣百分比" />
				</view>
				<view style="width: 80%;margin-left: 10%;">
					<text>说明:一次性批量分配给所有代理,例如:输入10%即可赚取下游10%的利润</text>
				</view>
				<view class="d-flex justify-space-around">
					<button size="mini" type="default" @click="submitF">取消</button>
					<button size="mini" type="primary" @click="submitFA">确认</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		removeToken
	} from '@/common/auth';
	export default {
		data() {
			return {
				commission_money:'0'
			}
		},
		methods: {
			handSettingShe(){
				uni.$uv.http.post('/logout').then(res => {
					// console.log(res,999999999);
					uni.showToast({
						title:'退出成功'
					})
					removeToken();
					let that = this;
					setTimeout(()=>{
						uni.$my.reLogin();;
					},500);
				}).catch(e => {
					console.log(e)
				})
				
			},
			handSettingGoods(){
				this.$refs.popupPiliangfy.open('center');
				uni.$uv.http.get('/cash/newCommission').then(res => {
					this.commission_money = res.data.totle;
				}).catch(e => {
					console.log(e)
				})
			},
			handSettingCommission(){
				this.$refs.popupPiliang.open('center');
				uni.$uv.http.get('/cash/newGoodsCommission').then(res => {
					this.commission_money = res.data.totle;
				}).catch(e => {
					console.log(e)
				})
			},
			submitFY(){
				this.$refs.popupPiliangfy.close();
			},
			submitF(){
				this.$refs.popupPiliang.close();
			},
			submitFYA(){
				uni.$uv.http.post('/cash/newCommission',{commission_money:this.commission_money}).then(res => {
					// this.commission_money = res.data.totle;
					uni.showToast({
						title:'设置成功'
					})
					this.$refs.popupPiliangfy.close();
				}).catch(e => {
					console.log(e)
				})
			},
			submitFA(){
				uni.$uv.http.post('/cash/newGoodsCommission',{commission_money:this.commission_money}).then(res => {
					// this.commission_money = res.data.totle;
					uni.showToast({
						title:'设置成功'
					})
					this.$refs.popupPiliang.close();
				}).catch(e => {
					console.log(e)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
		.setting-card{
			width: 100%;
			/* background:  #fff; */
			border-radius: 16rpx;
			padding: 20rpx;
			padding-bottom: 1rpx;
			.set-title{
				image{
					width: 50rpx;
					height: 50rpx;
				}
			}
		}
		
		.Piliangfypopup {
			width: 680rpx;
			padding: 10rpx;
			border-radius: 12rpx;
			background-color: #fff;
		
			.title {
				text-align: center;
				font-weight: 600;
				font-size: 32rpx;
				margin: 16rpx 0;
			}
		
			&-input {
				width: 80%;
				margin: 26rpx auto;
				padding: 8rpx;
				border: 1px solid #999;
				border-radius: 8rpx;
		
				input {
					padding-left: 8rpx;
					width: 100%;
				}
			}
		}
		::v-deep .uni-navbar__header-btns-right{
			display: none;
		}
		::v-deep .uni-navbar__header-btns-left{
			display: none;
		}
		::v-deep .uni-navbar__header-container{
			align-items: center;
		}
</style>
